package com.atguigu.jxc.controller;

import com.atguigu.jxc.entity.Unit;
import com.atguigu.jxc.service.UnitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("unit")
public class UnitController {

    @Autowired
    private UnitService unitService;
    /*请求URL：http://localhost:8080/unit/list
    请求参数：无
    请求方式：POST
    返回值类型：JSON
    返回值：Map<String,Object>
    */
    @PostMapping("list")
    public Map<String,Object> list(){
        Map<String, Object> map = new HashMap<>();
        List<Unit> list=unitService.getUnitList();
        List<Map<String,Object>> arr = new ArrayList<>();
        for (Unit unit : list) {
            Map<String, Object> map1 = new HashMap<>();
            map1.put("unitId",unit.getUnitId());
            map1.put("unitName",unit.getUnitName());
            arr.add(map1);
        }
        map.put("rows",arr);
        return map;
    }
}
